package com.wechatnotice.wechatnotice;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.web.client.RestTemplate;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author Admin
 */
@Slf4j
@EnableAdminServer
@SpringBootApplication
public class WechatNoticeApplication {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(WechatNoticeApplication.class, args);
        Environment env = application.getEnvironment();
        String hostAddr= InetAddress.getLocalHost().getHostAddress();
        String port=env.getProperty("server.port", "8080");
        log.info("\n-----------------------------------------------------------------\n\t" +
                        "应用 '{}' 启动成功! 访问连接:\n" +
                        "\tSwagger文档: \t\thttp://{}:{}/doc.html\n" +
                        "\tAdmin: \t\thttp://{}:{}/applications\n" +
                        "-----------------------------------------------------------------",
                env.getProperty("spring.application.name"),
                hostAddr,port,
                hostAddr,port
        );
    }

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

}
